<?php

namespace App\Jobs;

use App\Http\service\XcxService;
use App\Models\EggLog;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Cache;

class EggLogQrcodeJob implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
    private $data;
    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct(EggLog $eggLog)
    {
        $this->data=$eggLog;
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        Cache::lock("egg_log")->get(function (){
            $scene="type=get_egg&id=".$this->data->id;
            $path=(new XcxService())->create_xcx_code($scene);
            EggLog::where("id",$this->data->id)->update(["qrcode"=>$path]);
        });

    }
}
